/*********************************************************************************
 *FileName:  lin_signals.h
 *Author:  ChenJiehong
 *Version:  V1.0
 *Date: 2023-04-18
 **********************************************************************************/

#ifndef __lin_signals_H__
#define __lin_signals_H__

/***************************************Includes***********************************/
#include "lin_type.h"
#include "typedef.h"

/***************************************Macros***********************************/
#define __inline__        __inline

/* Template to generate read/write signal function prototypes */
#define L_SIGNAL(sigType, sigName, Frame_data)                             			\
    /** @name The signal "sigName" interaction */                               \
    /** Reads and returns the current value of the "sigName" signal.
       @return signal value */                                                  \
    static __inline__ sigType sigType ## _rd_ ## sigName(void);                 \
    static __inline__ sigType sigType ## _rd_ ## sigName(void)                  \
    {                                                                           \
        sigType s = Frame_data->sigName;                                        \
        return s;                                                               \
    }                                                                           \
                                                                                \
    /** Sets the new value of the "sigName" signal.
       @param[in] v new value
       @return void */                                                          \
    static __inline__ void sigType ## _wr_ ## sigName(sigType v);               \
    static __inline__ void sigType ## _wr_ ## sigName(sigType v)                \
    {                                                                           \
        Frame_data->sigName = v;                                                \
    }                                                                           \
		
	
#define L_FLAGS(bufName, flagName)																						\
    /** @name The flagType "baseName" flag interaction */                       \
    /** Returns a C boolean indicating the current state of the flagType "baseName" flag.
       @return [l_bool]:
       - zero - cleared;
       - non-zero - set. */                                                     \
    static __inline__ l_bool l_flg_tst_ ## flagName(void);                      \
    static __inline__ l_bool l_flg_tst_ ## flagName(void)                       \
    {                                                                           \
        l_bool s = bufName.flagName;                                            \
        return s;                                                               \
    }                                                                           \
                                                                                \
    /** Sets the current value of the flag specified by the flagType "baseName" to zero.
       @return void */                                                          \
    static __inline__ void l_flg_clr_ ## flagName(void);                        \
    static __inline__ void l_flg_clr_ ## flagName(void)                         \
    {                                                                           \
        bufName.flagName = false;                                               \
    }                                                                           		


		

/***************************************Variables***********************************/
	
typedef struct{
    l_u8 unused0_0  : 8;
    l_u8 unused8_0  : 8;
    l_u8 unused8_1  : 8;
    l_u8 ECU_EWV_PosSet  : 8;
	l_u8 ECU_EWV_MoveEn	 : 1;
    l_u8 unused32_0  : 7;
    l_u8 unused40_0  : 8;
    l_u8 unused40_1  : 8;
    l_u8 unused40_2  : 8;
} l_sl1_EWV_Set_data_t;


typedef struct __attribute__ ((packed)){
    l_bool EWV_RESP_ERR  : 1;
    l_bool EWV_OverVoltageFlt  : 1;
    l_bool EWV_OverCurrentFlt  : 1;
    l_bool EWV_OverTempFlt  : 1;
    l_bool EWV_UnderVoltageFlt  : 1;
    l_bool EWV_StallFlag  : 1;
	l_bool EWV_MotorSta  : 1;
    l_bool EWV_reverse0  : 1;
    l_u8 EWV_RESP_POS  : 8;
    l_u16 EWV_reverse1  : 16;
    l_u16 EWV_reverse2  : 16;
    l_u16 EWV_reverse3  : 16;
} l_sl1_EWV_Res_data_t;


typedef struct{

    l_bool s_EWV_RESP_ERR			: 1;
    l_bool f_EWV_Set 				: 1;
    l_bool f_EWV_Res 				: 1;
	l_bool unused_0 				: 5;
} l_sl1_flags_t;

extern l_sl1_EWV_Res_data_t *EWV_Res_data;	
extern l_sl1_EWV_Set_data_t *EWV_Set_data;	
	
L_SIGNAL(l_u8, ECU_EWV_PosSet, EWV_Set_data)
L_SIGNAL(l_u8, ECU_EWV_MoveEn, EWV_Set_data)

L_SIGNAL(l_bool, EWV_RESP_ERR, EWV_Res_data)
L_SIGNAL(l_bool, EWV_OverVoltageFlt, EWV_Res_data)
L_SIGNAL(l_bool, EWV_OverCurrentFlt, EWV_Res_data)
L_SIGNAL(l_bool, EWV_OverTempFlt, EWV_Res_data)
L_SIGNAL(l_bool, EWV_UnderVoltageFlt, EWV_Res_data)
L_SIGNAL(l_bool, EWV_StallFlag, EWV_Res_data)
L_SIGNAL(l_bool, EWV_MotorSta, EWV_Res_data)
L_SIGNAL(l_bool, EWV_reverse0, EWV_Res_data)
L_SIGNAL(l_u8, EWV_RESP_POS, EWV_Res_data)
L_SIGNAL(l_u16, EWV_reverse1, EWV_Res_data)
L_SIGNAL(l_u16, EWV_reverse2, EWV_Res_data)
L_SIGNAL(l_u16, EWV_reverse3, EWV_Res_data)



extern l_sl1_flags_t	l_sl1_flags;

L_FLAGS(l_sl1_flags, s_EWV_RESP_ERR)
L_FLAGS(l_sl1_flags, f_EWV_Set)
L_FLAGS(l_sl1_flags, f_EWV_Res)



void l_bool_wr_response_error(l_bool isError);
l_bool l_bool_rd_response_error(void);

/***************************************Functions***********************************/

#endif
/* [] END OF lin_api.h */
